<template>
  <!-- 添加或修改预警处置对话框 -->
  <div>
    <el-dialog :title="title" :visible.sync="dialogOpen" :before-close="cancel" width="500px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-form-item label="处置说明" prop="disposalInstructions">
          <el-input type="textarea" v-model="form.disposalInstructions" placeholder="请输入处置说明" />
        </el-form-item>
        <el-form-item label="图片" prop="imgUrl"><imageUpload v-model="form.imgUrl" /></el-form-item>
        <el-form-item label="附件" prop="fileUrl"><fileUpload v-model="form.fileUrl" /></el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="success" @click="send">发  送</el-button>
        <el-button :loading="buttonLoading" type="primary" @click="save">保  存</el-button>
        <el-button @click="cancel">取  消</el-button>
      </div>
    </el-dialog>

    <!-- 人员信息对话框 -->
    <el-dialog title="人员信息" :visible.sync="dialogVisible" width="500px" append-to-body>
      <el-table border v-loading="loading" :data="userDataList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="用户名称" align="center" key="userName" prop="userName" />
        <el-table-column label="用户昵称" align="center" key="nickName" prop="nickName" />

      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确  定</el-button>
        <el-button @click="dialogVisible = false">取  消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getInfoByWarningId, userList} from "@/api/zhgd/nWarningHnt";
import { listWarningDisposal,getWarningDisposal,addWarningDisposal,updateWarningDisposal,delWarningDisposal, } from "@/api/zhgd/warningDisposal";


export default {
  name:"Disposal",
  props:['open','warningId','warningType'],
  data(){
    return{
      // 遮罩层
      loading: true,
      buttonLoading:false,
      title:"title",
      // form:{},
      form:{
        disposalInstructions: undefined,
        imgUrl: undefined,
        fileUrl: undefined,
      },
      dialogOpen:false,
      // 人员信息
      dialogVisible: false,
      // 用户表格数据(人员信息表格数据)
      userDataList: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户名称`, visible: true },
        { key: 2, label: `用户昵称`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 4, label: `手机号码`, visible: true },
      ],
      // 日期范围
      dateRange: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    }
  },
  mounted(){
    this.dialogOpen = this.open;
  },

  created() {
    // this.getList();
  },

  methods:{
    /** 查询人员信息列表 */
     getList() {
      this.loading = true;
      userList().then(response => {
        this.userDataList = response.data;
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 人员信息确定,发送
    submitForm() {
      this.form.disposer = this.ids.join();
      this.form.warningId = this.warningId;
      this.form.warningType = this.warningType;
      // 发送，状态为3
      this.form.status = 3
      addWarningDisposal(this.form).then(res=>{
        this.dialogVisible = false;
        this.cancel();
        this.$emit('getList')
        this.$message.success("处置成功")
      })

    },
    // 取消
    cancel(){
      this.dialogOpen = false;
      this.$emit('closeDialog')
    },
    // 发送
    send(){
      this.dialogVisible = true;
      this.getList();

    },
    // 保存草稿
    save(){
    //   this.form.disposer = this.ids.join();
      this.form.warningId = this.warningId;
      this.form.warningType = this.warningType;
      // 保存，状态为2
      this.form.status = 2
      addWarningDisposal(this.form).then(res=>{
        this.dialogVisible = false;
        this.cancel();
        this.$emit('getList')
        this.$message.success("草稿保存成功")
      })
    },
      getInfoByWarningId(){
        console.log("________________________________getInfoByWarningId")
        if (!!this.form.warningId) {
          getInfoByWarningId(this.form.warningId,this.form.warningType).then(res => {
            this.form = res.data?res.data:this.form
            if (!this.dialogOpen) {
              this.dialogOpen = true
            }
          }).catch(error =>{})
        }
      },
  }
}
</script>

<style>

</style>
